const fs  = require('fs');
const { Transform } = require('stream');

exports.default = () => {
    // 读取文件
    const readStream = fs.createReadStream('normal.css');
    // 写入文件
    const writeStream = fs.createWriteStream('normal.min.css');

    // 文件转换
    const transform = new Transform({
        transform: (chunk, encoding, callback) => {
            // chunk 文件读取到的的内容 (Buffer)
            const input = chunk.toString();
            let output = '';
            //替换空格
            output = input.replace(/\s+/g, '');
            console.log('output', output);
            // 替换注释
            output = output.replace(/\/\*.+?\*\//g, '');
            console.log('output', output);
            callback(null, output);
        }
    });
    // 把读出来的文件写入
    readStream.pipe(transform)
        .pipe(writeStream);


    return readStream;
}